package com.waiting.leetcode;

/**
 * @Description 删除列表中的重复元素
 * @Author bjweitingting
 * @Date 2019/3/21
 **/
public class RemoveDuplicatesFromSortedListII82 {

    public ListNode deleteDuplicates(ListNode head) {
        if (head == null) return null;

        boolean removeHead = false;
        while (head.next != null && head.val == head.next.val) {
            removeHead = true;
            head.next = head.next.next;
        }
        head.next = deleteDuplicates(head.next);

        return removeHead ? head.next : head;
    }
}
